package com.peng.order.controller;

import com.peng.order.pojo.dto.OrderAddParam;
import com.peng.order.service.OrderService;
import com.peng.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单服务控制器
 * @author： Peng
 * @date： 2024/6/20
 * @version: 1.0
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单服务")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("创建订单")
    @PostMapping("/create")
    public JsonResult createOrder(@Validated @RequestBody OrderAddParam orderAddParam){
        log.debug("创建订单，参数：{}", orderAddParam);
        String orderNo = orderService.createOrder(orderAddParam);
        log.debug("创建订单结果：{}", orderNo);
        JsonResult<String> result = new JsonResult<>();
        result.setData(orderNo);
        result.setMsg("创建订单成功");
        result.setCode(2000);
        return result;
    }
}
